package com.wgts.wgts.mvp.view.activity.affrimorder;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.MyOrderDetailsEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/9/2217:01
 *
 */public class OrderChildRecycleAdapter extends RecyclerView.Adapter<OrderChildRecycleAdapter.ViewHold> {
    private Context context;
    private List<MyOrderDetailsEntity.Product> list;

    public OrderChildRecycleAdapter(Context context, List<MyOrderDetailsEntity.Product> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.order_shop_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        if (list.get(i).show){
            viewHold.shoppingSwipeList.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }else {
            viewHold.shoppingSwipeList.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
        }
        MoHuGlide.getInstance().glideImg(context, list.get(i).productSmallImage, viewHold.shoppingCarItemImage);
        viewHold.shoppingCarTitle.setText(list.get(i).productName);
        viewHold.shoppingCarTypeShow.setText(list.get(i).productStandard);
        viewHold.shoppingCarPrice.setText("￥" + list.get(i).productPrice);
        viewHold.orderShopNumber.setText("x" + list.get(i).productCount);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.shopping_car_item_image)
        ImageView shoppingCarItemImage;
        @BindView(R.id.shopping_car_title)
        TextView shoppingCarTitle;
        @BindView(R.id.shopping_car_type_show)
        TextView shoppingCarTypeShow;
        @BindView(R.id.shopping_car_price)
        TextView shoppingCarPrice;
        @BindView(R.id.order_shop_number)
        TextView orderShopNumber;
        @BindView(R.id.shopping_car_details)
        LinearLayout shoppingCarDetails;
        @BindView(R.id.shopping_swipe_list)
        LinearLayout shoppingSwipeList;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
